<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 17/4/26
 * Time: 下午8:22
 */
namespace Admin\Controller;
use Common\Controller\AdminBaseController;

class MenuController extends AdminBaseController{
    public function index(){
        $menu = M('menu');
        $list = $menu->field('title,pid,sort,link,status,id')->where(['type' => 1])->select();
        $list = getTree($list,0,0,'----');
        $this->assign('list',$list);
        $this->display();
    }
    public function changeMode(){
        if(IS_POST){
            $result = D('menu')->changeMode(I('post.id/d',0));
            $this->ajaxReturn($result);
        }
    }
    public function save(){
        if(IS_POST || IS_AJAX){
            $result = D('menu');
            $this->ajaxReturn($result->addMenu(I('post.')));
        }
    }
    public function Del(){
        if(IS_POST){
            $result = D('menu')->deleteMenu(I('post.id/d',0));
            $this->ajaxReturn($result);
        }
    }
    public function getMenu(){
        if(IS_POST){
            $result = D('menu')->menuList(I('post.id/d',0),'id,pid,title,link,sort,status');
            $this->ajaxReturn($result);
        }
    }
}